<template>
  <div class="edit-password-content">

    <van-form @submit="onSubmit">
      <van-field v-model="member_nickname"
                 label="新的昵称"
                 name="member_nickname"
                 type="text"
                 placeholder="请输入新的昵称"
                 :rules="[{require:true,message:'请输入您的昵称'}]"
                 clearable />
      <div style="margin: 16px;">
        <van-button round
                    block
                    native-type="submit"
                    class="submit-btn"
                    :disabled="member_nickname === ''">
          提交
        </van-button>
      </div>
    </van-form>

  </div>
</template>

<script>
import { editInformation } from '@/api/memberInfo'
import { formateTime } from '@/utils/utils'
import { mapState } from 'vuex'
export default {
  name: 'EditName',
  data() {
    return {
      member_nickname: this.$route.query.nickname || ''
    }
  },
  computed: {
    // 获取生日
    ...mapState({
      member_birthday: state =>
        formateTime(state.user.info.member_birthday * 1000, 'yyyy/MM/dd')
    })
  },
  methods: {
    onSubmit(formData) {
      formData.member_birthday = this.member_birthday
      editInformation(formData)
        .then(res => {
          this.$toast({
            type: 'success',
            message: res.message || '操作成功',
            onClose: () => {
              this.$router.go(-1)
            }
          })
          this.$store.commit('memberEdit', formData)
        })
        .catch(res => {
          this.$toast({
            type: 'fail',
            message: res.message || '修改失败，请重试'
          })
        })
    }
  }
}
</script>

<style lang="scss">
</style>
